package cn.wolfcode.wolf2w.query;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

@Getter
@Setter
public class TravelQuery extends QueryObject{

    public static final int ORDER_NEW = 1;
    public static final int ORDER_HOT = 2;

    private String destId;
    private int dayType = -1;
    private int perExpendType = -1;
    //mgr程序查询时，直接默认-1
    private int orderType = -1;

    public TravelCondition getDay(){
        return TravelCondition.DAY_MAP.get(dayType);
    }

    public TravelCondition getPerExpend(){
        return TravelCondition.PEREXPEND_MAP.get(perExpendType);
    }

    @Override
    public Pageable getPageable() {
        if(orderType == -1)
        {
            return super.getPageable();
        }
        else if(orderType == 1){
            return  PageRequest.of(super.getCurrentPage() - 1, super.getPageSize(),
                    Sort.Direction.DESC, "createTime");
        }else {
            return  PageRequest.of(super.getCurrentPage() - 1, super.getPageSize(),
                    Sort.Direction.DESC, "viewnum");
        }

    }
}
